<!DOCTYPE html>
<html>
<body>
    <h1>JavaScript 函数闭包</h1>
    <p>使用局部变量计数。</p>
    <p id="demo">0</p>
    <script>
        document.getElementById("demo").innerHTML = add();
        function add() {
            let counter = 0;
            function plus() {
                counter += 1;
            }
            plus();
            return counter;
        }
    </script>
</body>
</html>